package com.itcast.zk.locker;

import com.itcast.zk.locker.zk.ZKServerConfiguration;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.RetryNTimes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <p>Description: </p>
 * @date 
 * @author 
 * @version 1.0
 * <p>Copyright:Copyright(c)2020</p>
 */
@Configuration
public class GlobalSystemConfiguration {

    @Autowired
    private ZKServerConfiguration zkServerConfiguration;

    @Bean(initMethod = "start")
    public CuratorFramework curatorFramework() {
        return CuratorFrameworkFactory.newClient(
                zkServerConfiguration.getConnectString(),
                zkServerConfiguration.getSessionTimeoutMs(),
                zkServerConfiguration.getConnectionTimeoutMs(),
                new RetryNTimes(zkServerConfiguration.getRetryCount(), zkServerConfiguration.getElapsedTimeMs()));
    }
}
